#ifndef LOCALROSTER_H
#define LOCALROSTER_H

#include <QObject>
#include <QMap>
#include <QList>
#include <gloox/jid.h>
#include <gloox/rosterlistener.h>
#include <gloox/rostermanager.h>
#include <gloox/rosteritem.h>
#include <gloox/error.h>
#include "proto-xmpp-core/xmpproster.h"
#include "contacttlistwidget.h"
#include "contact.h"
#include "proto-xmpp-core/xmppclient.h"

#include <QDebug>


class LocalRoster : public QObject
{
    Q_OBJECT

    // data
    QMap<Contact*,ContactListItem*> contacts; // UNUSED!
    QList<RosterManager*> managers;

    // build contact and push it in contacts map
    Contact* addContact(gloox::JID jid);
public:
    // type definitions
    typedef std::pair<std::string, RosterItem*> RosterItemPair;

    // ctor
    explicit LocalRoster(QObject *parent = 0);

    // roster management
    void addRoster(XMPPRoster *roster);
    void removeRoster(XMPPRoster *roster);
    void addRosterManager(RosterManager *manager);
    void removeRosterManager(RosterManager *manager);

public slots:
    void itemAdded (const JID &jid);
    void itemSubscribed (const JID &jid);
    void itemRemoved (const JID &jid);
    void itemUpdated (const JID &jid);
    void itemUnsubscribed (const JID &jid);
    void rosterRecieved (const Roster &roster);
    void rosterPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg);
    void selfPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg);
    void subscriptionRequest (const JID &jid, const QString& msg);
    void unsubscriptionRequest (const JID &jid, const QString& msg);
    void nonrosterPresence (const Presence &presence);
    void rosterError (const IQ &iq);
signals:
    void itemAdded (const JID &jid, const JID &clientJid);
    void itemSubscribed (const JID &jid, const JID &clientJid);
    void itemRemoved (const JID &jid, const JID &clientJid);
    void itemUpdated (const JID &jid, const JID &clientJid);
    void itemUnsubscribed (const JID &jid, const JID &clientJid);
    void rosterRecieved (const Roster &roster, const JID &clientJid);
    void rosterPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg, const JID &clientJid);
    void selfPresence (const RosterItem &item, const QString& resource, Presence::PresenceType presence, const QString& msg, const JID &clientJid);
    void subscriptionRequest (const JID &jid, const QString& msg, const JID &clientJid);
    void unsubscriptionRequest (const JID &jid, const QString& msg, const JID &clientJid);
    void nonrosterPresence (const Presence &presence, const JID &clientJid);
    void rosterError (const IQ &iq, const JID &clientJid);
};

#endif // LOCALROSTER_H
